/*
 * Copyright (c) 2012 Johann Hanne
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef _CTYPE_H
#error Don't include ctype_istable.h directly, use ctype.h instead
#endif

#include <stdint.h>

#define _IS_BLANK  0x01
#define _IS_DIGIT  0x02
#define _IS_PRINT  0x04
#define _IS_LOWER  0x08
#define _IS_PUNCT  0x10
#define _IS_SPACE  0x20
#define _IS_UPPER  0x40
#define _IS_XDIGIT 0x80

#define _IS_ALPHA (_IS_UPPER|_IS_LOWER)
#define _IS_ALNUM (_IS_ALPHA|_IS_DIGIT)
#define _IS_GRAPH (_IS_PUNCT|_IS_ALNUM)

extern const uint8_t _is_table[];

#define iscntrl(c)  ((c) == 127 || ((c) & ~0x1f) == 0)
#define isprint(c)  (_is_table[(uint8_t)(c)] & _IS_PRINT)
#define isspace(c)  (_is_table[(uint8_t)(c)] & _IS_SPACE)
#define isblank(c)  (_is_table[(uint8_t)(c)] & _IS_BLANK)
#define isgraph(c)  (_is_table[(uint8_t)(c)] & _IS_GRAPH)
#define ispunct(c)  (_is_table[(uint8_t)(c)] & _IS_PUNCT)
#define isalnum(c)  (_is_table[(uint8_t)(c)] & _IS_ALNUM)
#define isalpha(c)  (_is_table[(uint8_t)(c)] & _IS_ALPHA)
#define isupper(c)  (_is_table[(uint8_t)(c)] & _IS_UPPER)
#define islower(c)  (_is_table[(uint8_t)(c)] & _IS_LOWER)
#define isdigit(c)  (_is_table[(uint8_t)(c)] & _IS_DIGIT)
#define isxdigit(c) (_is_table[(uint8_t)(c)] & _IS_XDIGIT)
